package com.tbit.uqbike.service.rpcservice.impl;

import cn.hutool.core.collection.CollUtil;
import com.tbit.uqbike.object.pojo.MachineAbnormal;
import com.tbit.uqbike.object.value.LoginInfo;
import com.tbit.uqbike.service.rpcservice.MachineAbnormalService;
import com.tbit.uqbike.webmanager.dao.core.MachineAbnormalDao;
import com.tbit.uqbike.webmanager.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 车辆故障
 *
 * @author Leon
 * 2019年11月16日 下午2:56:53
 */
@Service("machineAbnormalService")
public class MachineAbnormalServiceImpl implements MachineAbnormalService {
    @Autowired
    private MachineAbnormalDao machineAbnormalDao;

    @Override
    public List<MachineAbnormal> getByMachineId(LoginInfo info, Integer machineId) {
        return machineAbnormalDao.getByMachineId(machineId);
    }

    @Override
    public MachineAbnormal getByMachineIdAndType(Integer machineId, Integer abnormalType) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("machineId", machineId);
        params.put("abnormalType", abnormalType);

        return machineAbnormalDao.getByMachineIdAndType(params);
    }

    @Override
    public void insert(MachineAbnormal machineAbnormal) {
        machineAbnormal.setAbnormalTime(new Date());
        machineAbnormalDao.insert(machineAbnormal);
    }

    @Override
    public void del(Integer machineId, Integer abnormalType) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("machineId", machineId);
        params.put("abnormalType", abnormalType);

        machineAbnormalDao.del(params);
    }

    @Override
    public List<MachineAbnormal> groupByMachineIdAndType(Integer accountId, Integer abnormalType) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("accountId", accountId);
        params.put("abnormalType", abnormalType);

        return machineAbnormalDao.groupByMachineIdAndType(params);
    }

    @Override
    public void batchDelete(List<Integer> machineIds, List<Integer> abnormalTypes) {
        if (CollUtil.isEmpty(machineIds) || CollUtil.isEmpty(abnormalTypes)) {
            return;
        }
        Map<String, Object> params = new HashMap<>();
        params.put("machineIds", StringUtil.getListString(machineIds));
        params.put("abnormalTypes", StringUtil.getListString(abnormalTypes));
        machineAbnormalDao.batchDelete(params);
    }

}
